import * as types from "../action-types";
import {all, put, take,select} from 'redux-saga/effects';
import {delay} from '../utils';


export function* watchIncrementAsync() {

    for (let i = 0; i < 3; i++) {
        //take  监听一次ASYNC_INCREMENT动作  （take每次循环只监听一次，）
        const action = yield  take(types.ASYNC_INCREMENT)
        console.log(action)
        yield  put({type: types.INCREMENT})
    }
    alert('zu最多执行三次')
}


export function* watcthAndLog() {
    while (true) {
        let action = yield take('*')
        console.log(action)
        // select：   如何在saga中获取最新的状态树
        let state = yield select(state => state.counter);
        console.log(state)
    }
}

export  default function* () {
    yield  all([
        watcthAndLog(),   //监听每一个动作,当动作发生的时候打印日志
        watchIncrementAsync()   //  监听异步+1的动作
    ])
    console.log('111')
}
